import java.util.Stack;

public class T {

    public static void main(String[] args) {
        MinStack minStack=new MinStack();
        minStack.push(512);
        minStack.push(-1024);
        minStack.push(-1024);
        minStack.push(512);



        minStack.pop();
        minStack.pop();
        minStack.pop();

        System.out.println(minStack.stack2.peek());
//        System.out.println(minStack.stack2.isEmpty());

//        System.out.println(minStack.getMin());
//        minStack.pop();
//        System.out.println(minStack.getMin());
//
//        minStack.pop();
//        System.out.println(minStack.getMin());



    }
}


class MinStack {

    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MinStack() {
         stack1=new Stack<>();
         stack2=new Stack<>();

    }

    public void push(int val) {
        if(stack1.isEmpty()){
            stack1.push(val);
            stack2.push(val);
        }else {
            stack1.push(val);
            if(stack2.peek()>=val){
                stack2.push(val);
            }
        }

    }

    public void pop() {
        if(stack1.pop().equals(stack2.peek())){
            stack2.pop();
        }



    }

    public int top() {
        return stack1.peek();

    }

    public int getMin() {

        return stack2.peek();


    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */